const fs = require('fs');
var data = '今天是2023-01-06';
fs.writeFile('./files/1.txt', data, error => {
    console.log(error);
})


fs.writeFile('./files/1.txt', data, {
        encoding: "utf8",
        flag: "w",
        mode: 0o666
    },
    (err) => {
        if (err)
            console.log(err);
        else {
            console.log("File written successfully\n");
            console.log("The written has the following contents:");
            console.log(fs.readFileSync("movies.txt", "utf8"));
        }
    });

/* 
写入失败的错误信息提示
    [Error: ENOENT: no such file or directory, open 'M:\files\11.txt'] {
    errno: -4058,
    code: 'ENOENT',
    syscall: 'open',
    path: 'M:\\files\\11.txt'
    }
*/
fs.writeFile('M:/files/11.txt', data, error => {
    console.log(error);
})